<?php
namespace app\api\controller;

use lib\Cache;
use lib\Request;
use lib\Response;

class Common {

    protected $tokenPrefix = 'UserToken';
    protected $request;
    protected $data;
    protected $post;
    protected $get;
    protected $uid;

    function __construct(){
        $this->request = new Request();
        $this->data = $this->request->data;
        $this->post = $this->request->post;
        $this->get = $this->request->get;
        if(!$this->data['token'] && ($this->request->controller != 'user' && $this->request->action != 'minireg')){
            return Response::error('illegal request!');
        }
        $this->data['page'] = $this->data['page'] ? (int)$this->data['page'] : 1;
        $this->data['page'] = $this->data['page'] ? (int)$this->data['page'] : 1;
        $this->uid = Cache::get("{$this->tokenPrefix}_{$this->data['token']}");
    }

}